#!/bin/csh
# Usage: msub job.hera

#MSUB -l nodes=4
### MSUB -l qos=exempt
#MSUB -l partition=hera
#MSUB -l walltime=1:00:00
#MSUB -q pbatch
#MSUB -V
#MSUB -o /g/g99/toth2/Tmp/CRASH/SCALING/run/runlog

date
cd /g/g99/toth2/Tmp/CRASH/SCALING/run

# run CRASH (the number of processors is already specified above)
# switch on BATL and set plot directory just before the run starts
perl -pi -e 's/^BATL/\#BATL/' PARAM.in
perl -pi -e 's/.*NamePlotDir/plot\t\tNamePlotDir/' PARAM.in

# Number of cores = 16 times the number of nodes
srun -n64 CRASH.exe

# load opacity tables in next run(s)
perl -pi -e 's/^LOOKUPTABLE/\#LOOKUPTABLE/; s/save/load/' PARAM.in

if(-e plot_128/log_n000020.log && -e plot_256/log_n000020.log)then
    echo 'we have both'
    ${HOME}/Tmp/CRASH/share/Scripts/DiffNum.pl -r=3e-5 \
        plot_128/log_n000020.log plot_256/log_n000020.log > scaling.diff
    cat runlog_128 runlog_256 > scaling.log
    setenv COPY Sites/CRASH_SCALING/`date +%Y%m%d`
    if(-s scaling.diff)then
	scp scaling.diff ${HEROT}:${COPY}.error
    endif
    scp scaling.log  ${HEROT}:${COPY}.log
    ssh ${HEROT} chmod go+r ${COPY}.\*
endif

exit
